package com.ponhu.ea2.stockcenter.provider.service.entity.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ponhu.ea2.stockcenter.provider.constants.CommonConstant;
import com.ponhu.ea2.stockcenter.provider.entity.StockInventoryChangeSettings;
import com.ponhu.ea2.stockcenter.provider.mapper.StockInventoryChangeSettingsMapper;
import com.ponhu.ea2.stockcenter.provider.service.entity.StockInventoryChangeSettingsService;
import com.ponhu.ea2.stockcenter.provider.support.service.RedisSupportService;
import com.ponhu.ea2.stockcenter.provider.utils.RedisUtils;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class StockInventoryChangeSettingsServiceImpl
        extends ServiceImpl<StockInventoryChangeSettingsMapper, StockInventoryChangeSettings>
        implements StockInventoryChangeSettingsService {

    @Autowired
    private RedisSupportService redisSupportService;

    @Override
    public StockInventoryChangeSettings getInventoryChangeSettingsByType(Integer recordChannel, Integer actionType) {

        String redisKey = RedisUtils.getRedisKey(CommonConstant.INVENTORY_CHANGE_SETTINGS,
                recordChannel.toString(), actionType.toString());

        return redisSupportService.getObjFromRedis(redisKey, () -> {
            LambdaQueryWrapper<StockInventoryChangeSettings> queryWrapper = Wrappers
                    .lambdaQuery(StockInventoryChangeSettings.class)
                    .eq(StockInventoryChangeSettings::getRecordChannel, recordChannel)
                    .eq(StockInventoryChangeSettings::getActionType, actionType);

            return getOne(queryWrapper);
        }, StockInventoryChangeSettings.class);
    }
}




